<?php

/* @var $this yii\web\View */

use yii\helpers\Html;
use yii\web\JsExpression;
use daixianceng\echarts\ECharts;
use yii\widgets\ActiveForm;

$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-detail">
    <div>
        <?php
        $readonly=true;
        if(\Yii::$app->authManager->checkAccess(Yii::$app->user->id, 'admin'))
        {
            $readonly=false;
        }
        ?>
        <?= Html::label('航空公司', 'airline', []) ?>
        <?= Html::input('text', 'airline', $airline, ['id'=>'myairline','readonly'=>$readonly]) ?>
        <?= Html::label('代理人', 'agent', []) ?>
        <?= Html::input('text', 'agent', $agent, ['id'=>'myagent']) ?>
        <?= Html::button('查询', ['id' => 'chaxun']) ?>
    </div>

    <div>
    <?= ECharts::widget([
        'responsive' => true,
        'options' => [
            'style' => 'height: 400%;width: 100%;'
        ],
        'pluginOptions' => [
            'option' => [
                'title' => [
                    'text' => '代理人'.$agent.'在航空公司'.$airline.'的销售情况'
                ],
                'tooltip' => [
                    'trigger' => 'axis'
                ],
                'legend' => [
                    'data' => ['销售额', '销售量']
                ],
                'grid' => [
                    'left' => '3%',
                    'right' => '4%',
                    'bottom' => '3%',
                    'containLabel' => true
                ],
                'toolbox' => [
                    'feature' => [
                        'dataView'=> ['readOnly'=> true],
                        'magicType'=> ['type'=> ['line', 'bar']],
                        'saveAsImage' => []
                    ]
                ],
                'xAxis' => [
                    'name' => '日期',
                    'type' => 'category',
                    'boundaryGap' => false,
                    'data' => [],
                ],
                'yAxis' => [
                    'type' => 'value'
                ],
                'series' => [
                    [
                        'name' => '销售额',
                        'type' => 'line',
                        'stack' => '总量',
                        'data' => [],
                    ],
                    [
                        'name' => '销售量',
                        'type' => 'line',
                        'stack' => '总量',
                        'data' => [],
                    ],

                ]
            ]
        ]
    ]); ?>
    </div>

    <?php $this->beginBlock('myjs') ?>
    function getdata() {
    var echarts_w0 = echarts.init(document.getElementById('w0'));
    echarts_w0.showLoading();
    var airline=$("#myairline").val();
    var agent=$("#myagent").val();
    $.ajax({
    type: "POST",
    url: '<?=\Yii::getAlias('@web')?>/site/ajaxagent',
    dataType: "json",
    data:
    {
    csrfToken:"<?= Yii::$app->request->csrfToken ?>",
    airline:airline,
    agent:agent,
    },
    success: function(data)
    {
            echarts_w0.hideLoading();
            echarts_w0.setOption(
            {
            "title": { "text": "代理人"+data.agent+"在航空公司"+data.airline+"的销售情况" },
            "tooltip": { "trigger": "axis" },
            "legend": { "data": ["销售额", "销售量"] },
            "grid": { "left": "3%", "right": "4%", "bottom": "3%", "containLabel": true },
            "toolbox": { "feature": { "dataView": { "readOnly": true }, "magicType": { "type": ["line", "bar"] }, "saveAsImage": [] } },
            "xAxis":
            {
            "name": "日期", "type": "category", "boundaryGap": false,
            "data":data.X
            },
            "yAxis": { "type": "value" },
            "series":
            [
            { "name": "销售额", "type": "line", "stack": "总量",
            "data":data.mY
            },
            { "name": "销售量", "type": "line", "stack": "总量",
            "data":data.cY
            }
            ]
            }
            );
    },
    error: function(jqXHR)
    {
    alert("发生错误：" + jqXHR.status);
    },
    });
    }

    getdata();
    $("#chaxun").click(function(){
    getdata();
    });
    <?php $this->endBlock() ?>
    <?php $this->registerJs($this->blocks['myjs'], \yii\web\View::POS_READY); ?>

</div>
